<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>会员管理</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <%@include file="../include/commonFile.jsp" %>
    <style type="text/css">
        #view table th, #view table td{
            padding: 9px 10px!important;
        }
    </style>
</head>
<body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">

            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <ul class="layui-tab-title">
                    <c:forEach items="${types}" var="type">
                        <li ${input.type == type.key ? 'class="layui-this"':''}
                                data-type="${type.key}">${type.value}</li>
                    </c:forEach>
                </ul>
                <div class="layui-tab-content">
                    <form class="layui-form" action="${ctx}/member/membermgmt/list.do" id="myForm" method="post">
                        <input type="hidden" name="type" id="type" value="${input.type}"/>
                        <input type="hidden" name="pageNo" id="pageNo"/>
                        <input type="hidden" name="partentId" value="${partentId}"/>
                        <div class="f-search-bar">
                            <div class="search-container">
                                <ul class="search-form-content">
                                    <li class="form-item-inline">
                                        <label class="search-form-lable">手机号</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="mobile" autocomplete="off" class="layui-input"
                                                   value="${input.mobile}" placeholder="请输入查询手机号">
                                        </div>
                                    </li>
                                    <li class="form-item-inline">
                                        <label class="search-form-lable">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp地区</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="area" autocomplete="off" class="layui-input"
                                                   value="${input.area}" placeholder="请输入查询地区">
                                        </div>
                                    </li>
                                    <c:if test="${!isChild || isXzgsAdmin}">
                                        <li class="form-item-inline"><label class="search-form-lable">所属机构</label>
                                            <div class="layui-input-inline">
                                                <select name="memberGroupId">
                                                    <option value="">全部</option>
                                                    <c:forEach var="memberGroup" items="${memberGroupList}">
                                                        <option value="${memberGroup.id}" ${input.memberGroupId == memberGroup.id ? 'selected="selected"' : ''}>${memberGroup.realname}</option>
                                                    </c:forEach>
                                                </select>
                                            </div>
                                        </li>
                                    </c:if>

                                </ul>
                                <ul class="search-form-content">
                                    <li class="form-item-inline">
                                        <label class="search-form-lable">编&nbsp&nbsp&nbsp号</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="userSerial" autocomplete="off" class="layui-input"
                                                   value="${input.userSerial}" placeholder="请输入会员编号">
                                        </div>
                                    </li>
                                    <li class="form-item-inline">
                                        <label class="search-form-lable">昵称</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="nickName" autocomplete="off" class="layui-input"
                                                   value="${input.nickName}" placeholder="请输入查询昵称">
                                        </div>
                                    </li>
                                    <li class="form-item-inline"><label class="search-form-lable">性别</label>
                                        <div class="layui-input-inline">
                                            <select name="sex">

                                                <option value=""
                                                        <c:if test="${input.sex == null}">selected=selected</c:if>>全部
                                                </option>
                                                <option value="0"
                                                        <c:if test="${input.sex == 0}">selected=selected</c:if>>女
                                                </option>
                                                <option value="1"
                                                        <c:if test="${input.sex == 1}">selected=selected</c:if>>男
                                                </option>
                                            </select>
                                        </div>
                                    </li>
                                </ul>
                                <ul class="search-form-content">
                                    <li class="form-item"><label class="search-form-lable">加入时间</label>
                                        <div class="check-btn-inner" id="timeType">
                                            <a id="all" href="javascript:void(0);"
                                               onclick="setTimeType($(this),0,'#myForm')" ${empty input.timeType || input.timeType == 0 ? 'class="active"' : ''}>全部</a>
                                            <a href="javascript:void(0);"
                                               onclick="setTimeType($(this),1,'#myForm')" ${input.timeType == 1 ? 'class="active"' : ''}>今天</a>
                                            <a href="javascript:void(0);"
                                               onclick="setTimeType($(this),2,'#myForm')" ${input.timeType == 2 ? 'class="active"' : ''}>本周内</a>
                                            <a href="javascript:void(0);"
                                               onclick="setTimeType($(this),3,'#myForm')" ${input.timeType == 3 ? 'class="active"' : ''}>本月内</a>
                                            <input type="hidden" name="timeType" value="${input.timeType}"/>
                                        </div>
                                        <div class="layui-inline">
                                            <div class="layui-input-inline">
                                                <input class="layui-input" type="text" name="createStart"
                                                       value="${empty input.createStart ? '' : fn:substring(input.createStart, 0, 10)}"
                                                       placeholder="开始日">
                                            </div>
                                            -
                                            <div class="layui-input-inline">
                                                <input class="layui-input" type="text" name="createEnd"
                                                       value="${empty input.createEnd ? '' : fn:substring(input.createEnd, 0, 10)}"
                                                       placeholder="截止日">
                                            </div>
                                        </div>
                                    </li>
                                    <li class="form-item-inline">
                                        <div class="sub-btns">
                                            <c:if test="${(input.type == 0 && isCommune)||(isXzgsAdmin)}">
                                                <a class="layui-btn layui-btn-danger"
                                                   href="${ctx}/notify/template/membermgmt/list.do?targetId=${partentId}">
                                                    短信推送
                                                </a>
                                            </c:if>
                                            <a class="layui-btn layui-btn-danger"
                                               href="javascript:txz.expireCheck('', function() { exportExcelData() })">导出EXCEL</a>
                                            <a class="layui-btn layui-btn-danger"
                                               href="javascript:submitFunction('#myForm')">查询</a>
                                            <a class="layui-btn layui-btn-normal"
                                               href="javascript:resetFunction('#myForm')">重置</a>
                                        </div>
                                    </li>
                                    <%--<li class="form-item-inline">--%>
                                        <%--<a class="layui-btn layui-btn-danger layui-btn-sm"--%>
                                           <%--id="importResultBtn">导入人员成绩EXCEL</a>--%>
                                        <%--<form id="userForm" method="post" class="dn" action="${ctx}/member/integral/userIntegral/branchMemberImport.do" enctype="multipart/form-data">--%>
                                            <%--<input type="file" name="uploadFile" id="upload_input" single--%>
                                                   <%--accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" />--%>
                                        <%--</form>--%>
                                    <%--</li>--%>
                                </ul>
                            </div>
                        </div>
                    </form>
                    <div class="my-act-list-content">
                        <ul id="view">
                            <table class="layui-table">
                                <colgroup>
                                    <col width="70px">
                                    <col width="80px">
                                    <col>
                                    <col width="70px">
                                    <col width="120px">
                                    <col>
                                    <col>
                                    <col>
                                    <col>
                                    <col>
                                    <c:if test="${(isChild == false && isCommune == true) ||(isXzgsAdmin)}">
                                        <col width="90px">
                                    </c:if>
                                    <c:if test="${(isCommune && input.type == 0) ||(isXzgsAdmin)}">
                                        <col width="80px">
                                        <col>
                                    </c:if>
                                </colgroup>
                                <thead>
                                <tr>
                                    <th>序号</th>
                                    <th>编号</th>
                                    <th>昵称</th>
                                    <th>性别</th>
                                    <th>手机号</th>
                                    <th>微信号</th>
                                    <th>公司</th>
                                    <th>区域</th>
                                    <th>职务</th>
                                    <th>加入时间</th>
                                    <c:if test="${(isChild == false && isCommune == true) ||(isXzgsAdmin)}">
                                        <th>所属机构</th>
                                    </c:if>
                                    <c:if test="${(isCommune  && input.type == 0)||(isXzgsAdmin)}">
                                        <th>审核状态</th>
                                        <th>操作</th>
                                    </c:if>
                                </tr>
                                </thead>
                                <tbody>
                                <c:forEach var="member" items="${list}" varStatus="st">
                                    <tr>
                                        <td>${page.limit * (page.page-1) + st.count}</td>
                                        <td>${member.userSerial}</td>
                                        <td class="table-member"
                                            onclick="openDialogShow('用户名片','${ctx}/system/member/memberView.do?id=${member.memberId}','400px','470px')">
                                            <div class="member-cell">
                                                <div class="member-logo common-img">
                                                    <img src="<c:if test="${ member.logo!= null}">${member.logo}?imageMogr2/auto-orient/crop/126x126</c:if>"
                                                         alt="" onerror="txz.errImg(this)" onload="txz.imgLoad(this)">
                                                </div>
                                                <div class="member-name ellipsis-1"><a class="blue"
                                                                                       title="${member.nickName}"
                                                                                       href="javascript:void(0);">${member.nickName}</a>
                                                </div>
                                            </div>
                                        </td>
                                        <td>${member.sex}</td>
                                        <td>${member.mobile}</td>
                                        <td>${member.wechatNum}</td>
                                        <td>${member.company}</td>
                                        <td>${member.area}</td>
                                        <td>${member.job}</td>
                                        <td>${member.createTime}</td>
                                        <c:if test="${(isChild == false && isCommune == true )||(isXzgsAdmin)}">
                                            <td>
                                                ${member.realname}<c:if test="${member.partnerType == true}"><span class="red">*</span></c:if>
                                            </td>
                                        </c:if>
                                        <c:if test="${(isCommune && input.type == 0)||((isXzgsAdmin))}">
                                            <td>
                                                <c:choose>
                                                    <c:when test="${member.checkStatus == 0}">
                                                        <span style="color: blue;">待审核</span>
                                                    </c:when>
                                                    <c:when test="${member.checkStatus == 1}">
                                                        <span style="color: green;">审核通过</span>
                                                    </c:when>
                                                    <c:otherwise>
                                                        <span class="red">审核拒绝</span>
                                                    </c:otherwise>
                                                </c:choose>
                                            </td>
                                            <td class="opts-btns tb-opts">
                                                <div class="comm-opts">
                                                    <c:if test="${member.checkStatus==0}">
                                                        <a href="javascript:checkMember('${member.pmId}','1')"
                                                           class="green" target="_self">通过</a>
                                                        <a href="javascript:checkMember('${member.pmId}','2')"
                                                           class="red" target="_self">拒绝</a>
                                                        <a target="_self" class=""
                                                           href="javascript:openDialogShow('查看推荐人','${ctx}/system/member/recommendMemberView.do?pmId=${member.pmId}','400px','470px')">
                                                            查看推荐人
                                                        </a>
                                                    </c:if>
                                                    <c:if test="${member.checkStatus==1}">
                                                        <a href="${ctx}/member/membermgmt/form.do?pmId=${member.pmId}&pageNo=${page.page}">
                                                            编辑
                                                        </a>
                                                        <a class="green"
                                                           href="${ctx}/member/integral/userIntegral/list.do?pmId=${member.pmId}">
                                                            查看积分
                                                        </a>
                                                        <a class="green"
                                                           href="${ctx}/member/integral/userIntegral/recommendPersonList.do?pmId=${member.pmId}">
                                                            查看推荐的人
                                                        </a>
                                                        <a class="qr-btn" href="javascript:txz.openQrDialog({
                                                                title:'扫码二维码可预览分享',
                                                                detailList:[{
                                                                    title:'个人名片二维码',
                                                                    url:'${member.qrCodeUrl}',
                                                                    link:''
                                                                }]
                                                            })">查看二维码</a>
                                                        <a target="_self" class=""
                                                           href="javascript:openDialog(' ${member.nickName} 的推荐人','${ctx}/member/membermgmt/bindingRRView.do?memberId=${member.memberId}',
                                                                '550px','500px')">
                                                            绑定推荐关系
                                                        </a>
                                                        <c:if test="${(isChild == false) ||(isXzgsAdmin)}">
                                                            <a target="_self" class=""
                                                               href="javascript:openDialog('更改所属','${ctx}/member/membermgmt/setTag.do?memberId=${member.memberId}&partnerId=${member.partnerId}',
                                                                '700px','600px')">
                                                                分配分社
                                                            </a>
                                                        </c:if>
                                                    </c:if>
                                                </div>
                                            </td>
                                        </c:if>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                        </ul>
                    </div>
                    <div id="page_content" class="page-container"></div>
                </div>
            </div>
        </div><!--底部-->
        <%@include file="../include/footer.jsp" %>
    </section>


</div>

<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript" src="${ctx}/script/common/table_option.js"></script>
<script type="text/javascript">

    var form;
    $(function () {
        //加载分页
        loadPageNew({
            elem: 'page_content',
            totalCount: '${page.totalCount}',
            limit: '${page.limit}',
            page: '${page.page}'
        });
        layui.use(['laydate', 'form'], function () {
            var laydate = layui.laydate;
            form = layui.form;
            // 查询发布日期
            var start = {
                elem: 'input[name=createStart]'
            };

            var end = {
                elem: 'input[name=createEnd]'
            };
            laydate.render(start);
            laydate.render(end);

        });
        layui.use(['form', 'element'], function () {
            var element = layui.element;

            element.on('tab', function (data) {
                $('input[name=type]').val($(this).data('type'));
                submitFunction('#myForm');
            });
        });


        var importResultBtn = document.getElementById("importResultBtn");
        var upload_input = document.getElementById("upload_input");
        importResultBtn.addEventListener('click', function (e) {

            upload_input.click();

            e.preventDefault();
        }, false);

        upload_input.addEventListener('change', function (e) {
            console.log(e.target.files[0].name);
            //loading层
            myLoadIndex = layer.msg('努力导入中,请耐心等待...', {
                icon: 16,
                shade: 0.1,
                time: 1
            });
            var formData = new FormData();
            formData.append("uploadFile", $("#upload_input")[0].files[0]);

            $.ajax({
                url: "${ctx}/member/integral/userIntegral/branchMemberImport.do",
                type: 'post',
                data: formData,
                processData: false, // 告诉jQuery不要去处理发送的数据
                contentType: false, // 告诉jQuery不要去设置Content-Type请求头
                beforeSend: function () {
                    console.log("正在进行，请稍候");
                },
                success: function () {
                    layer.msg('数据维护成功', {title: '通知', icon: 1, time: 2000}, function () {
                        window.location.reload();
                    });
                },
                error: function (res) {
                    layer.msg('数据维护失败：' + res.description, {title: '通知', icon: 2, time: 2000});
                }
            });
            e.preventDefault();
        }, false);
    })


    function exportExcelData() {
        layer.confirm('确认要导出Excel吗?', {
            icon: 3,
            title: '系统提示'
        }, function (index) {
            var url = "${ctx}/member/membermgmt/listExport.do";
            var loadIndex = layer.load(1, {
                shade: [0.1, '#fff'] //0.1透明度的白色背景
            });
            $.post(url, $("#myForm").serialize(), function (res) {
                top.layer.close(loadIndex);
                if (res.success) {
                    window.location.href = res.data;
                } else {
                    util.layerMsgError(res.description)
                }
            });
            top.layer.close(index);
        });
    }

    function openDialog(title, url, width, height, target) {
        layer.open({
            type: 2,
            area: [width, height],
            title: title,
            maxmin: true, //开启最大化最小化按钮
            content: url,
            btn: ['确定', '关闭'],
            yes: function (index, layero) {
                var body = layer.getChildFrame('body', index);
                var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                var inputForm = body.find('#inputForm');
                var top_iframe;
                if (target) {
                    top_iframe = target;//如果指定了iframe，则在改frame中跳转
                } else {
                    top_iframe = '_parent';//获取当前active的tab的iframe
                }
                inputForm.attr("target", top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示

                if (iframeWin.contentWindow.doSubmit()) {
                    setTimeout(function () {
                        top.layer.close(index);
                    }, 100);//延时0.1秒，对应360 7.1版本bug

                    setTimeout(function () {
                        window.location.reload();
                    }, 200);
                }

            },
            cancel: function (index) {
            }
        });
    }

    //审核功能
    function checkMember(pmId, state) {
        $.post("${ctx}/member/membermgmt/checkMember.do", {
            pmId: pmId,
            state: state
        }, function (data) {
            if (data.success == true) {
                util.layerAlertSuccess("操作成功", function () {
                    window.location.reload();
                })
            } else {
                util.layerAlertError("操作失败")
            }
        });
    }
</script>
<script type="text/javascript">
    txz.initHeader({
        nav: [{
            name: '会员管理',
            curr: true
        }],
        info: '<span class="f12">共<b id="totalCount">${page.totalCount}</b>条记录</span>'
        <c:if test="${(isCommune && input.type == 0) || isXzgsAdmin }">
        , btns: [{
            name: '添加会员',
            icon: 'add',
            href: '${ctx}/member/membermgmt/form.do',
            isCheckExpire: true
        }]
        </c:if>
    });
</script>
</body>
</html>